/*
 * Created by: Peter Weissbrod
 * Created: Saturday, November 03, 2007
 */
using System;
using System.Collections.Generic;
using Castle.ActiveRecord;
using Castle.Components.Validator;
using Utils;

namespace EntityLayer.Entities
{
    /// <summary>
    /// The course data
    /// </summary>
    [ActiveRecord("Courses")]
    public class Course : ActiveRecordBase<Course>
    {
        #region members
        private int courseID = Nulls.ID;
        private DateTime postDate = Nulls.DateTime;
        private IList<SalesItem> salesItems = new List<SalesItem>();
        private string courseNameAndNumber = Nulls.String;
        #endregion

        #region properties
        [PrimaryKey(PrimaryKeyType.Identity, "CourseID",UnsavedValue = "0") ]
        public int CourseID
        {
            get { return courseID; }
            set { courseID = value; }
        }
        [Property(NotNull = true, Length = 255), ValidateNonEmpty, ValidateIsUnique]
        public string CourseNameAndNumber
        {
            get { return courseNameAndNumber; }
            set { courseNameAndNumber = value; }
        }
        [Property(NotNull = true)]
        public DateTime PostDate
        {
            get { return postDate; }
            set { postDate = value; }
        }
        [HasAndBelongsToMany(typeof(SalesItem), Table = "SalesItemCourses", ColumnKey = "CourseID", ColumnRef = "SalesItemID"
            , Lazy = true,Inverse = true)]
        public IList<SalesItem> SalesItems
        {
            get { return salesItems; }
            set { salesItems = value; }
        }
        #endregion

        #region methods
        public Course()
        {
        }
        public Course(DateTime postDate, string courseNameAndNumber)
        {
            this.postDate = postDate;
            this.courseNameAndNumber = courseNameAndNumber;
        }
        #endregion
    }
}